package com.haojg.conf;

import com.haojg.service.CustomerMcpService;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;

@Configuration
public class ChatClientConf {

    @Resource
    private List<CustomerMcpService> customerMcpServices;

    @PostConstruct
    public void init() {
        System.out.println(customerMcpServices);
    }

    @Bean
    public ToolCallbackProvider customerToolCallbackProvider() {
        return MethodToolCallbackProvider
                .builder()
                .toolObjects(customerMcpServices)
                .build();
    }

    @Bean
    public ChatClient chatClient(ChatClient.Builder builder, ToolCallbackProvider toolCallbackProvider) {
        return builder
                .defaultSystem("你一个用户信息查询系统，支持使用用户名查找用户信息，使用工号查询用户信息。")
                .defaultTools(toolCallbackProvider.getToolCallbacks())
                .build();
    }

}
